package ewan.android.droidjockey;


import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.Activity;
import android.app.FragmentTransaction;
import android.content.Context;
import android.os.Bundle;

public class SongList extends Activity implements ActionBar.TabListener {
	

	public void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		final ActionBar bar = getActionBar();
		
		bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
		bar.setDisplayShowTitleEnabled(false);
		bar.setDisplayShowHomeEnabled(false);
		Tab tab = bar
				.newTab()
				.setText("Songs")
				.setTabListener(
						new TabListener<SongListFragment>(this, "song",
								SongListFragment.class));
		bar.addTab(tab);

		tab = bar
				.newTab()
				.setText("Albums")
				.setTabListener(
						new TabListener<AlbumListFragment>(this, "album",
								AlbumListFragment.class));
		bar.addTab(tab);

		tab = bar
				.newTab()
				.setText("Artists")
				.setTabListener(
						new TabListener<ArtistListFragment>(this, "artist",
								ArtistListFragment.class));
		bar.addTab(tab);
		
		tab = bar
				.newTab()
				.setText("Playlist")
				.setTabListener(
						new TabListener<PlayListFragment>(this, "playlist",
								PlayListFragment.class));
		bar.addTab(tab);


		if (savedInstanceState != null) {
			bar.setSelectedNavigationItem(savedInstanceState.getInt("tab"));
		}
		
		
	}
	
	/*interface BackPressed {

		public void onBackPressed();

	}
*/
	
	@Override
	protected void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);

		if (getActionBar().getSelectedTab().getText().equals("Songs")){
			outState.putInt("tab",  0);
		}
		else if (getActionBar().getSelectedTab().getText().equals("Albums")){
			outState.putInt("tab",  1);
		}
		else if (getActionBar().getSelectedTab().getText().equals("Artists")){
			outState.putInt("tab",  2);
		}
		else if (getActionBar().getSelectedTab().getText().equals("Playlist")){
			outState.putInt("tab",  3);
		}
	}
	

	public void onTabReselected(Tab tab, FragmentTransaction ft) {
		System.out.println(tab.getText());
		if (tab.getText().equals("Songs")){
			System.out.println("Songs");
		}
		if (tab.getText().equals("Albums")){
			System.out.println("Albums");
		}
		if (tab.getText().equals("Artists")){
			System.out.println("Artists");
		}
		if (tab.getText().equals("Playlist")){
			System.out.println("Playlist");
		}
	}

	public void onTabSelected(Tab tab, FragmentTransaction ft) {
		System.out.println(tab.getText());
		if (tab.getText().equals("Songs")){
			System.out.println("Songs");
		}
		if (tab.getText().equals("Albums")){
			System.out.println("Albums");
		}
		if (tab.getText().equals("Artists")){
			System.out.println("Artists");
		}
		if (tab.getText().equals("Playlist")){
			System.out.println("Playlist");
		}
		}
	
	public void onTabUnselected(Tab tab, FragmentTransaction ft) {

	}



}
